#include <iostream>
#include <unistd.h>
#include <csignal>
#include <sys/types.h>

using namespace std;

void handle_sigusr1(int sig)
{
    cout << "[Parent] Received SIGUSR1 (" << sig << ")" << endl;
}

int main()
{
    signal(SIGUSR1, handle_sigusr1);
    pid_t pid = fork();
    if(pid < 0)
    {
        perror("fork error");
        return 1;
    } 
    else if (pid == 0)
    {
        sleep(1);
        cout << "[Child] Sending SIGUSR1 to parent (PID " << getpid() << ")" << endl;
        kill(getppid(), SIGUSR1);
    }
    else
    {
        cout << "[Parent] Waiting for signal..." << endl;
        pause();
        cout << "[Parent] Done." << endl;
    }
    return 0;
}
